Part Number Hot Search : 
SSM9916J 1N4148WT IC0604 DC110 T2SC10 1010C L5235 DTC114
Product Description
Full Text Search
 

To Download AN431 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
 (R)
APPLICATION NOTE
USING ST6 ANALOG INPUTS FOR MULTIPLE KEY DECODING
J.Stockinger
INTRODUCTION The ST6 on-chip Analog to Digital Converter (ADC) is a useful peripheral integrated into the silicon of the ST6 family members. The flexibility of the I/O port structure allows the multiplexing of up to 13/8 Analog Inputs into the converter in a 28/20 pin device for the ST6210/15 2k ROM and ST6220/25 4k ROM families, enabling full freedom in circuit layout. Many other members of the ST6 family also offer the Analog to Digital converter. One of the more novel and practical applications of this converter, is to decode a number of keys. The technique is to connect the keys by resistive voltage dividers to the converter inputs. An example of key detection using 10 keys is illustrated in this note. Using the Analog to Digital converter in this fashion does not require a static current and avoids false key detection. BASIC CIRCUIT The basic circuit of the key decoder consists of a pull-up resistor connected to the ST6 Analog to Digital converter input with the first key directly switching to ground. The following keys are then connected in sequence to the ADC input through serial resistors. The number of keys which may be detected depends on the tolerance of the resistors used. It can be seen that if more than one key is pressed at the same time, the key detected will be the next key in the chain closest to the ADC input. This also allows the keys in the keyboard to be prioritized.
AN431 / 09,92
1/14
ANALOG KEYBOARD
PRINCIPLE OF OPERATION The combination of the pull-up resistor, the serial resistors and the pressed key form a resistive voltage divider, generating a different voltage at the ADC input for each key pressed. The serial resistors are selected in order to give an equal distribution of voltage between V DD and VSS for each switch combination to give the best noise margin between keys. When a key is pressed, the voltage at the ADC input is given by the activated voltage divider. This analog voltage is converted by the ADC and the digital value is used to determine which switch is closed. Two successive conversions may be made to avoid the influence of key bounce. Figure 1. Analog Keyboard resistor key matrix
Figure 2. Multiple key press
2/14
(R)
ANALOG KEYBOARD
Table 1. Key code ranges Key Nr
1 2 3
Valid Code Range
0 18-1A 30-33 49-4E 63-68 7C-81 97-9B B0-B4 CA-CD E5-E6
Distance to next key
24 22 22 21 20 22 21 22 24 25
4
5 6 7 8 9 10
If the top key is pressed, the voltage measured is always zero. For n keys, the resistor values should be selected such that the voltage for the second key from top is VDD/n, for the 3rd - 2xVDD/n, for the 4th 3xVDD/n and for the nth - (n-1)xVDD/n. Resistor values from the tolerance set used must be selected to meet this requirement. The recommended resistor values for a 10-key keyboard with 2% resistors from the E24 series, used with a 10k pull-up resistor, are shown in table 2. If more current can be allowed, then a 1k resistor can be used in which case the serial resistor values should be divided by 10.
Table 2. Used resistors and Tolerance Resistor
Rp R1 R2 R3 R4 R5 R6 R7 R8 R9
Value ()
10000 1100 1300 1800 2400 3300 5100 8200 16000 51000
-2% ()
9800 1078 1274 1764 2352 3234 4998 8036 15680 49980
+2% ()
10200 1122 1326 1836 2448 3366 5202 8364 16320 52020
3/14
(R)
ANALOG KEYBOARD
PRACTICAL LIMITATIONS Theoretically, for an ideal power supply, ADC and resistors, 255 keys could be detected. Practically however, it is necessary to take into account potential errors coming from: - the power supply - the key resistivity - the resistor tolerance - the ADC error The power supply tolerance can normally be neglected providing noise is not present at a frequency within or above the frequency range of the RC delay of the resistive divider, as the ADC reference is normally provided by the power supply of the ST6. For ST6 family members with external ADC reference voltage inputs, AVDD and AVSS may be used instead of VDD and VSS. The sensitivity of the key can normally be neglected, as the resistance of the divider is high in comparison to it. If the key resistivity is significant, it should be added to the "serial" pull-down resistance of the different dividers. The key resistivity variation must also be added to the tolerance of the serial pull-down resistor (see resistor tolerance following). The resistor tolerance affects the tolerance of the dividers. Two situations must be taken into account: a) minimum value of pull-up combined with maximum values of pull-down = maximum voltage of the divider at the ADC input. b) maximum value of the pull-up combined with the minimum values of pull-down = minimum voltage at the ADC input. These two cases give the maximum voltage variation of each divider (see Table 3). The voltage variation ranges of two dividers must not overlap otherwise the key cannot be decoded, even with an ideal converter. Table 3. Effective Divider Resistors
Active Key S0 S1 S2 S3 S4 S5 S6 S7 S8 S9 R -2% () 0 1078 2352 4116 6468 9702 14700 22736 38416 88396 R +2% () 0 1122 2448 4284 6732 10098 15300 23664 39984 92004
Realistic converters require a margin between the range of variation. In the case of a significant variation in the key resistivity, the maximum resistivity of the key has to be added to the value of the pulldown resistor in case a). For case b) no error needs to be added as the resistivity cannot be less than 0 .
4/14
(R)
ANALOG KEYBOARD
The linearity of the ADC converter of the ST6 is normally specified for 2 LSB, therefore a minimum distance of 4 LSB is needed between the edges of the resistance tolerance ranges. For the best results, a minimum of 8 LSB should be used (see Table 4). Table 4. Voltage at the ADC-Input,Converter Results (5V supply)
V (Rxmin-Rpmax) Active Key V S0 S1 S2 S3 S4 S5 S6 S7 S8 S9 0.00 0.48 0.94 1.44 1.94 2.44 2.95 3.45 3.95 4.48 hex. 00 18 30 49 63 7C 97 B0 C9 E5 dec. 0 24 48 73 99 124 151 176 201 229 V 0.00 0.51 1.00 1.52 2.04 2.54 3.05 3.54 4.02 4.52 hex. 00 1A 33 4E 68 81 9B B4 CD E6 dec. 0 26 51 78 104 129 155 180 205 230 V (Rxmax-Rpmin)
Table 5. AD-Converter Results
Active Key S0 S1 S2 S3 S4 S5 S6 S7 S8 S9 R Error Range (LSB) 0 2 3 4 5 5 5 4 3 2 Distance to next Key 24 22 22 21 20 22 21 22 24 25 Valid Key Range 0-0 18-1A 30-33 49-4E 63-68 7C-81 97-9B B0-B4 C9-CD E5-E6
5/14
(R)
ANALOG KEYBOARD
EXTENSION FOR WAKE UP ST6 family members with the Analog input capacity can also generate a wakeup operation (from WAIT or STOP modes) on the pressing of a key. This can be achieved by a modification of the circuit shown in figure 1. The pull-up resistor is not connected to VDD but to an additional I/O port bit. During key polling, this additional port bit is set to output mode active high, thus effectively switching VDD to the pull-up resistor. The resistance of the pull-up resistor must be high enough to give no significant voltage drop, or the resulting error must be calculated and taken into account. The other I/O bit is used as the Analog input to the ADC as in the original circuit. During the wait for the key press, the first I/O pin, used to pull the pull-up resistor high to VDD while polling, is switched into a high impedance state (e.g. open drain output mode). The second I/O pin, used as the ADC input while polling, is switched to the interrupt input with pullup mode. The internal pull-up is in the range of 100k, in comparison to the 1k 10k of the external resistor used during polling. If any key is now pressed an interrupt will be generated if the voltage at the second I/O pin is below the Schmitt trigger low level threshold. The serial resistors in the keyboard chain must not be too high in this case, therefore the maximum number of keys is reduced in comparison to the normal mode.
Figure 3. Keyboard wake-up circuit
Figure 4. Keyboard reading
Figure 5. Interrupt configuration
6/14
(R)
ANALOG KEYBOARD
APPENDIX A: Key Input by Polling
;************************************************************************** ;* * ;* SGS-THOMSON GRAFING * ;* * ;* APPLICATION NOTE 431 ST6 * ;* * ;* Use of ADC inputs for multiple key decoding * ;* * ;* With the inbuilt A/D converter of any ST6 it is easy to * ;* implement a small routine which enables ONE port pin, con* ;* figured as an ADC input, to decode up to ten different switches* ;* All that is necessary is to set one port pin as an ADC input * ;* Then the program runs in an endless loop until one of the * ;* connected keys is pushed. * ;* The value from the ADC data register is then used to decide * ;* how the program will continue,on reaction to the key-push. * ;* * ;************************************************************************** ;***REGISTERS*** ddrpb orpb drpb adr adcr a .def .def .def .def .def .def 0c5h 0cdh 0c1h 0d0h 0d1h 0ffh ;port B data direction register ;port B option register ;port B data register ;A/D data register ;A/D control register ;accumulator ;***CONSTANTS*** inpall peg1_2 peg2_3 peg3_4 peg4_5 peg5_6 peg6_7 peg7_8 peg8_9 peg9_10 .equ .equ .equ .equ .equ .equ .equ .equ .equ .equ 000h 00ch 025h 03eh 058h 072h 08ch 0a5h 0beh 0d9h ;used for setting all pins input ;border to distinguish between switch1 ;border to distinguish between switch2 ;border to distinguish between switch3 ;border to distinguish between switch4 ;border to distinguish between switch5 ;border to distinguish between switch6 ;border to distinguish between switch7 ;border to distinguish between switch8 ;border to distinguish between switch9
and and and and and and and and and
switch2 switch3 switch4 switch5 switch6 switch7 switch8 switch9 switch10
7/14
(R)
ANALOG KEYBOARD
ldi ldi ldi
ldi
loop:
jrr
ld
sw1:
cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp
;sets all port B pins low -- all input ;option register: ;sets bit b0 high, the rest low drpb,01h ;direction register: ;sets bit b0 high, the rest low ;-- pb0 becomes analog input ; pb1-7 become input with pull-up, but ; are not used here (only one pin may be ; analog input for A/D at the same time) adcr,30h ;A/D control register: ; 0011 0000 -- -activate A/D converter ; -start conversion ; -disable A/D interrupt 6,adcr,loop ;loop until the End Of Conversion bit is ;set (indicator that a conversion has ;been completed) a,adr ;load acc with the result of the A/D ;conversion ;now the result is compared with the ;switches a,peg1_2 ;compare with peg1_2 sw2 ;A/D result was smaller than peg1_2 s1 ; -- switch1 was pressed: jump to s1 a,peg2_3 sw3 s2 a,peg3_4 sw4 s3 a,peg4_5 sw5 s4 a,peg5_6 sw6 s5 ;compare with peg2_3 ;A/D result was smaller than peg2_3 ; -- switch2 was pressed: jump to s2 ;compare with peg3_4 ;A/D result was smaller than peg3_4 ; -- switch3 was pressed: jump to s3 ;compare with peg4_5 ;A/D result was smaller than peg4_5 ; -- switch4 was pressed: jump to s4 ;compare with peg5_6 ;A/D result was smaller than peg5_6 ; -- switch5 was pressed: jump to s5
ddrpb,inpall orpb,01h
sw2:
sw3:
sw4:
sw5:
8/14
(R)
ANALOG KEYBOARD
sw6:
cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp jp
a,peg6_7 sw7 s6 a,peg7_8 sw8 s7 a,peg8_9 sw9 s8 a,peg9_10 sw10 s9 s10
;compare with peg6_7 ;A/D result was smaller than peg6_7 ; -- switch6 was pressed: jump to s6 ;compare with peg7_8 ;A/D result was smaller than peg7_8 ; -- switch7 was pressed: jump to s7 ;compare with peg8_9 ;A/D result was smaller than peg8_9 ; -- switch8 was pressed: jump to s8 ;compare with peg9_10 ;A/D result was smaller than peg9_10 ; --> switch9 was pressed: jump to s9 ;A/D result was greater than peg9_10 ; -- switch10 was pressed: 0 ;
sw7:
sw8:
sw9:
sw10:
;*** the routines handling to the reaction to the individual key presses ;*** are to be included here. s1: s2: s3: s4: s5: s6: s7: s8: s9: s10:
9/14
(R)
ANALOG KEYBOARD
APPENDIX B: Key Input by Interrupt
;************************************************************************** ;* * ;* SGS-THOMSON GRAFING * ;* * ;* APPLICATION NOTE 431 ST6 * ;* * ;* Use of ADC inputs for multiple key decoding * ;* * ;* With the inbuilt A/D converter of any ST6 it is easy to * ;* implement a small routine with which you can recognize * ;* if one of nine connected keys is pushed by creating an * ;* interrupt. The program can then decide how it will react * ;* to the key pushed. * ;* * ;* * ;************************************************************************** ;***REGISTERS*** ddrpb orpb drpb ior adr adcr a .def .def .def .def .def .def .def 0c5h 0cdh 0c1h 0c8h 0d0h 0d1h 0ffh ;port B data direction register ;port B option register ;port B data register ;interrupt option register ;A/D data register ;A/D control register ;accumulator ;***CONSTANTS*** inpall peg1_2 peg2_3 peg3_4 peg4_5 peg5_6 peg6_7 peg7_8 peg8_9 .equ .equ .equ .equ .equ .equ .equ .equ .equ 000h 00ch 025h 03eh 058h 072h 08ch 0a5h 0beh ;used for setting all pins input ;border to distinguish between switch1 ;border to distinguish between switch2 ;border to distinguish between switch3 ;border to distinguish between switch4 ;border to distinguish between switch5 ;border to distinguish between switch6 ;border to distinguish between switch7 ;border to distinguish between switch8
and and and and and and and and
switch2 switch3 switch4 switch5 switch6 switch7 switch8 switch9
; en_kint (enable key-interrupt) sets the registers in a way that pushing ; any key will cause an interrupt. This subroutine must be called to ; re-enable the key interrupt (e.g. after handling the key service routine)
10/14
(R)
ANALOG KEYBOARD
en_kint: ldi ldi ldi ddrpb,inpall orpb,02h drpb,01h ;sets all port B pins low -- all input ;option register: ; sets bit b1 high, the rest low ;data register: ; sets bit b0 high, the rest low ;-- pb0 becomes input, no pull-up, no int ; pb1 becomes input with pull-up and int. ; pb2-7 become input with pull-up, but ; are not used here ;interrupt option register: ;-- set D4: enable all interrupts ; reset D5: falling edge on int.input(#2) ;return to the calling address
ldi
ior,10h
ret
;*** hd_kint (handle key interrupt) interrupt service routine ;*** evaluates the data resulting in pushing a key. ;*** Interrupt vector #2 (0ff4h and 0ff5h) must point (jump) to hd_kint. hd_kint: ldi ldi drpb,03h ddrpb,01h ;data register: ; 0000 0011 ;data direction register: ; 0000 0001 ; -- pb0 becomes output ;option register: ; 0000 0011 ; -- pb0: push-pull output ; -- pb1: ADC-input ; pb2-7 become input with pull-up, but ; are not used here ;A/D control register: ; 0011 0000 -- -activate A/D converter ; -start conversion ; -disable A/D interrupt ;waits until the End Of Conversion ; bit is set (indicator that a conversion ; has been completed) ;load acc with the result of the A/D ; conversion ;now the result is compared with the ; values which represent the different ; switches
ldi
orpb,03h
ldi
adcr,30h
loop:
jrr
6,adcr,loop
ld
a,adr
11/14
(R)
ANALOG KEYBOARD
sw1:
cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp cpi jrnz jp jp
a,peg1_2 sw2 s1 a,peg2_3 sw3 s2 a,peg3_4 sw4 s3 a,peg4_5 sw5 s4 a,peg5_6 sw6 s5 a,peg6_7 sw7 s6 a,peg7_8 sw8 s7 a,peg8_9 sw9 s8 s9
;compare with peg1_2 ;A/D result was smaller than peg1_2 ; -- switch1 was pressed: jump to s1 ;compare with peg2_3 ;A/D result was smaller than peg2_3 ; -- switch2 was pressed: jump to s2 ;compare with peg3_4 ;A/D result was smaller than peg3_4 ; -- switch3 was pressed: jump to s3 ;compare with peg4_5 ;A/D result was smaller than peg4_5 ; -- switch4 was pressed: jump to s4 ;compare with peg5_6 ;A/D result was smaller than peg5_6 ; -- switch5 was pressed: jump to s5 ;compare with peg6_7 ;A/D result was smaller than peg6_7 ; -- switch6 was pressed: jump to s6 ;compare with peg7_8 ;A/D result was smaller than peg7_8 ; -- switch7 was pressed: jump to s7 ;compare with peg8_9 ;A/D result was smaller than peg8_9 ; -- switch8 was pressed: jump to s8 ;A/D result was bigger than peg8_9 ; -- switch9 was pressed: jump to s9 ;
sw2:
sw3:
sw4:
sw5:
sw6:
sw7:
sw8:
sw9:
;*** The routines handling the reaction to the individual key presses ;*** are to be included here
12/14
(R)
ANALOG KEYBOARD
s1: s2: s3: s4: s5: s6: s7: s8: s9: ;*** Each routine must end with the following lines in order to enable ;*** another interrupt when the next key is pressed. call en_kint ; enable another interrupt reti
return:
13/14
(R)
ANALOG KEYBOARD
THE SOFTWARE INCLUDED IN THIS NOTE IS FOR GUIDANCE ONLY. SGSTHOMSON SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM USE OF THE SOFTWARE.
Information furnished is believed to be accurate and reliable. However, SGS-THOMSON Microelectronics assumes no responsability for the consequences of use of such information nor for any infringement of patents or other rights of third parties which may result from its use. No license is granted by implication or otherwise under any patent or patent rights of SGS-THOMSON Microelectronics. Specifications mentioned in this publication are subject to change without notice. This publication supersedes and replaces all information previously supplied. SGS-THOMSON Microelectronics products are not authorized for use as critical components in life support devices or systems without the express written approval of SGS-THOMSON Microelectronics. (c) 1994 SGS-THOMSON Microelectronics - All rights reserved. Purchase of I C Components by SGS-THOMSON Microelectronics conveys a license under the Philips I C Patent. Rights to use these components in an I2C system is granted provided that the system conforms to the I2C Standard Specification as defined by Philips. SGS-THOMSON Microelectronics Group of Companies Australia - Brazil - France - Germany - Hong Kong - Italy - Japan - Korea - Malaysia - Malta - Morocco - The Netherlands Singapore - Spain - Sweden - Switzerland - Taiwan - Thailand - United Kingdom - U.S.A.
2 2
14/14
(R)


▲Up To Search▲   

 
Price & Availability of AN431

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X